export default class LayerMap {
    layerMap
    constructor() {
        this.layerMap = new Map()
    }

    hasKey(key) {
        return this.layerMap.has(key)
    }
    addLayer(key, layer) {
        if (this.hasKey(key)) {
            throw new Error('图层已存在')
        } else {
            this.layerMap.set(key, layer)
        }
    }

    getLayer(key) {
        const value = this.layerMap.get(key)
        if (value) {
            return value
        }
        throw new Error('图层不存在')
    }

    removeLayer(key) {
        this.layerMap.delete(key)
    }

    clearLayer() {
        this.layerMap.clear()
    }
}
